<?php
class Index extends MY_Controller{
    public function __construct() {
        parent::__construct();
        $this->load->helper('main_helper');
		$this->load->model('model_home');
		$this->load->model('model_rate');
		$this->load->model('model_ticket');
    }
    public function index(){
		$data['title'] = "Vietnam railway";
		$data['template'] = "home";
		$data['abouts'] = $this->abouts();
		$data['listtrains'] = $this->listtrains(20);
		$data['destinations'] = $this->destinations(6);
		$data['listregions'] = $this->listregions();
		$data['listquestion'] = $this->faqs();
		$destination = array();
		foreach($data['listregions'] as $items){
			$abc = $this->model_rate->getdestina($items['region_id']);
			if($abc != NULL){
			  $destination[$items['region_title']] = $this->model_rate->getdestina($items['region_id']);
			  
			}
		}
		foreach($destination as $k => $items){
			if($items != NULL){
				foreach($items as $key => $val){
					$tickets = $this->model_ticket->getcheaptickets($val['desti_id']);
					if($tickets != NULL){
						$destination[$k][$key]['softseat'] = $tickets['softseat'];
						$destination[$k][$key]['hardberth'] = $tickets['hardberth'];
						$destination[$k][$key]['softberth'] = $tickets['softberth'];
						$destination[$k][$key]['vipberth'] = $tickets['vipberth'];
					}else{
						$destination[$k][$key]['softseat'] = 0;
						$destination[$k][$key]['hardberth'] = 0;
						$destination[$k][$key]['softberth'] = 0;
						$destination[$k][$key]['vipberth'] = 0;
					}
				}
			}
		}
		//$this->debug($destination);
		$data['destinas'] = $destination;
  		$this->load->view("layout",$data);
    }
}
?>